<?php

namespace app\controller\sys;

use app\BaseController;
use app\model\Merchant;
use think\Response;

class Mer extends BaseController
{
    public function save(): Response
    {
        return $this->success($this->app->make(Merchant::class)->addOrUpdate());
    }

    public function lst(): Response
    {
        return $this->success($this->app->make(Merchant::class)->lst());
    }

    public function detail(): Response
    {
        return $this->success($this->app->make(Merchant::class)->find($this->request->param('id')));
    }

    public function balance(): Response
    {
        return $this->success($this->app->make(Merchant::class)->balanceUpdate());
    }

    public function state(): Response
    {
        return $this->success($this->app->make(Merchant::class)->updateState());
    }

    public function allState(): Response
    {
        $ids = $this->request->param('ids');
        $state = $this->request->param('state');
        return $this->success(Merchant::whereIn('id', $ids)->update(['state' => $state]));
    }

    public function search(): Response
    {
        return $this->success($this->app->make(Merchant::class)->where('state', 1)->column("id,name"));
    }

    public function bindSearch(): Response
    {
        return $this->success($this->app->make(Merchant::class)->where('state', 1)->whereRaw("aid is null or aid = ''")->column("id `key`,name `label`"));
    }
}
